<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp_lib/init.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>权限管理</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp" />
<jsp:include page="/WEB-INF/jsp_lib/extjs.jsp" />

<jsp:include page="add.jsp" />
<jsp:include page="edit.jsp" />

<script type="text/javascript">
	dataStore = Ext.create('Ext.data.TreeStore', {
		proxy : {
			type : 'ajax',
			url : "loc_data.htm",
			reader : {
				type : 'json',
			}
		}
	});
	var menuPanel = Ext.create('Ext.tree.Panel', {
		store : dataStore,
		width : 400,
		title : "地区管理",
		border : true,
		rootVisible : false,
		animCollapse : true,
		rootVisible : false,
		animate : true,
		listeners : {
			itemcontextmenu : function(view, rec, node, index, e) {
				e.stopEvent();
				e.preventDefault();

				// 添加一个节点（叶子）  
				var chlidNodeClickMenu = Ext.create('Ext.menu.Menu', {
					items : [ {
						text : '新增子菜单',
						icon : jcapp.getIcon("add.png"),
						handler : function() {
							var up_code = rec.get("code");
							var up_name = rec.get("text");
							myAdd(up_code, up_name);
						}
					}, {
						text : '新增同级菜单',
						icon : jcapp.getIcon("vcard_add.png"),
						handler : function() {
							var up_code = rec.parentNode.get("code");
							var up_name = rec.parentNode.get("text");
							if(up_code== undefined ){
								up_code = "";
							}
							myAdd(up_code, up_name);
						}
					}, {
						text : '修改菜单',
						icon : jcapp.getIcon("vcard_edit.png"),
						handler : function() {
							myEdit(rec.get("kid"));
						}
					}, {
						text : '删除菜单',
						icon : jcapp.getIcon("vcard_delete.png"),
						handler : function() {
							myDel(rec.get("kid"));
						}
					} ]
				});

				//menu的showAt，不要忘记  
				chlidNodeClickMenu.showAt(e.getPoint());

				return false;
			}
		}
	//#listeners
	});//#menuPanel

	Ext.onReady(function() {
		menuPanel.render(Ext.getBody());
	});

	function myDel(kid) {
		Ext.Msg.confirm("提示:", "确定删除选定的记录?", function(e) {
			if (e == "yes") {
				Ext.Ajax.request({
					url : "del.htm?kid=" + kid,
					success : function(response) {
						var json = Ext.util.JSON.decode(response.responseText);
						Ext.Msg.alert("提示", json.tip.msg);
						dataStore.load();
					},
					failure : function(response) {
						Ext.Msg.alert("提示", "操作失败!");
					}
				});
			}//#if
		});
	}//#myDel
</script>
</head>
<body>

</body>
</html>